package com.iknow.ui.model;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.data.Word;
import com.iknow.db.IKnowDataBase;
import com.iknow.view.widget.TranslatePanel;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class StrangeWordAdapter extends BaseAdapter
{
  private LayoutInflater inflater;
  private View.OnClickListener itemClick;
  private boolean mBShowCrashBox;
  private Context mContext;
  private OnWordRemoveCallback mOnWordRemoveCallback;
  private View.OnClickListener stateItemClick;
  protected TranslatePanel translatePanel;
  private List<Word> words = null;

  public StrangeWordAdapter(Context paramContext)
  {
    this.inflater = null;
    this.mBShowCrashBox = true;
    this.itemClick = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (!(IKnow.IsNetAviable()))
          Toast.makeText(StrangeWordAdapter.access$1(this.this$0), StrangeWordAdapter.access$1(this.this$0).getString(2131361878), 0).show();
        while (true)
        {
          return;
          String str = ((StrangeWordAdapter.ViewHolder)paramView.getTag()).key.getText().toString();
          if (this.this$0.translatePanel == null)
            this.this$0.translatePanel = new TranslatePanel(StrangeWordAdapter.access$1(this.this$0));
          this.this$0.translatePanel.setDisplay(str);
        }
      }
    };
    this.stateItemClick = new View.OnClickListener(this)
    {
      public void onClick()
      {
        ArrayList localArrayList = new ArrayList();
        localArrayList.add((Word)paramView.getTag());
        IKnow.mIKnowDataBase.removeWord(localArrayList);
        if (!(IKnow.IsNetAviable()));
        while (true)
        {
          do
          {
            return;
            StrangeWordAdapter.access$2(this.this$0, IKnow.mIKnowDataBase.getWord(0, 100));
            this.this$0.notifyDataSetChanged();
          }
          while (StrangeWordAdapter.access$3(this.this$0) == null);
          StrangeWordAdapter.access$3(this.this$0).fireOnWordRemoved((Word)paramView.getTag());
        }
      }
    };
    this.inflater = ((LayoutInflater)paramContext.getSystemService("layout_inflater"));
    this.words = new ArrayList();
    this.mContext = paramContext;
  }

  private boolean bExitWord(Word paramWord)
  {
    int i;
    Iterator localIterator = this.words.iterator();
    if (!(localIterator.hasNext()))
      i = 0;
    while (true)
    {
      Word localWord;
      do
      {
        return i;
        localWord = (Word)localIterator.next();
      }
      while (!(localWord.getKey().equalsIgnoreCase(paramWord.getKey())));
      ArrayList localArrayList = new ArrayList();
      localArrayList.add(localWord);
      IKnow.mIKnowDataBase.removeWord(localArrayList);
      i = 1;
    }
  }

  private boolean bInList(String paramString)
  {
    int i;
    Iterator localIterator = this.words.iterator();
    if (!(localIterator.hasNext()))
      i = 0;
    while (true)
    {
      do
        return i;
      while (!(((Word)localIterator.next()).getKey().equalsIgnoreCase(paramString)));
      i = 1;
    }
  }

  public void addWord(Word paramWord)
  {
    if (!(bExitWord(paramWord)))
    {
      this.words.add(paramWord);
      new ArrayList();
    }
  }

  public void addWordWithoutDB(Word paramWord)
  {
    if (bInList(paramWord.getKey()));
    while (true)
    {
      return;
      this.words.add(paramWord);
    }
  }

  public void bindView(View paramView, Word paramWord)
  {
    if (paramWord == null);
    while (true)
    {
      ViewHolder localViewHolder;
      do
      {
        return;
        localViewHolder = (ViewHolder)paramView.getTag();
        localViewHolder.info = paramWord;
        String str = paramWord.getKey();
        localViewHolder.key.setText(str);
        localViewHolder.lang.setText(paramWord.getLang());
        localViewHolder.def.setText(paramWord.getDef());
      }
      while (!(this.mBShowCrashBox));
      localViewHolder.state.setTag(paramWord);
    }
  }

  public void clearAll()
  {
    this.words.clear();
  }

  public View createView()
  {
    ViewHolder localViewHolder = new ViewHolder(this);
    View localView = this.inflater.inflate(2130903070, null);
    localViewHolder.key = ((TextView)localView.findViewById(2131296379));
    localViewHolder.lang = ((TextView)localView.findViewById(2131296382));
    localViewHolder.def = ((TextView)localView.findViewById(2131296380));
    localViewHolder.state = ((ImageButton)localView.findViewById(2131296381));
    if (this.mBShowCrashBox)
      localViewHolder.state.setOnClickListener(this.stateItemClick);
    while (true)
    {
      localView.setTag(localViewHolder);
      localView.setOnClickListener(this.itemClick);
      return localView;
      localViewHolder.state.setVisibility(8);
    }
  }

  public int getCount()
  {
    return this.words.size();
  }

  public Word getItem(int paramInt)
  {
    return ((Word)this.words.get(paramInt));
  }

  public long getItemId(int paramInt)
  {
    return paramInt;
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    Word localWord = getItem(paramInt);
    if (paramView == null)
      paramView = createView();
    paramView.setBackgroundResource(2130837606);
    bindView(paramView, localWord);
    return paramView;
  }

  public List<Word> getWordList()
  {
    return this.words;
  }

  public void removeWord(int paramInt)
  {
    this.words.remove(paramInt);
  }

  public void setBShowCrashBox(boolean paramBoolean)
  {
    this.mBShowCrashBox = paramBoolean;
  }

  public void setOnWordRemoveCallback(OnWordRemoveCallback paramOnWordRemoveCallback)
  {
    this.mOnWordRemoveCallback = paramOnWordRemoveCallback;
  }

  public void setWordList(List<Word> paramList)
  {
    this.words = paramList;
  }

  public static abstract interface OnWordRemoveCallback
  {
    public abstract void fireOnWordRemoved(Word paramWord);
  }

  public class ViewHolder
  {
    TextView def;
    Word info;
    TextView key;
    TextView lang;
    ImageButton state;
  }
}